﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Contexts;
using Infraestruturex.BaseLibrary;

namespace Compilex.Syntatic.Declarations
{
    public class ExpressionStack
    {
        public SyntaticContext Context { get; set; }
        public SimpleStack<BooleanExpression> Stack { get; set; }
        public BooleanExpression JustPopped { get; private set; }
        public BooleanExpression Current
        {
            get
            {
                if (Stack.Count > 0)
                    return Stack.Peek();
                else
                    return null;
            }
        }

        public int Count { get { return Stack.Count; } }

        public ExpressionStack(SyntaticContext context)
        {
            this.Context = context;
            this.Stack = new SimpleStack<BooleanExpression>();
        }

        public void AddSimpleIdOperand()
        {
            this.Current.AddSimpleIdOperand();
        }

        public void AddArrayElementOperand()
        {
            Current.AddArrayElementOperand();
        }

        public void AddConstantOperand()
        {
            this.Current.AddConstantOperand();
        }

        public void AddArithmeticOperator()
        {
            this.Current.AddArithmeticOperator();
        }

        public void AddBooleanOperator()
        {
            this.Current.AddBooleanOperator();
        }

        public void AddBooleanLiteral()
        {
            this.Current.AddBooleanLiteral();
        }

        public void ArithmeticExpressionEnded()
        {
            this.Current.ArithmeticExpressionEnded();
        }

        public void EndExpression()
        {
            this.Current.EndExpression();
            this.JustPopped = Stack.Pop();
        }

        public void AddEqualityOperator()
        {
            this.Current.AddEqualityOperator();
        }

        public void AddComparisonOperator()
        {
            this.Current.AddComparisonOperator();
        }

        public void StartNewExpression()
        {
            this.Stack.Push(new BooleanExpression(this.Context));
        }

        public void CancelExpression()
        {
            Stack.Pop();
        }

        public void BExpressionEnded()
        {
            EndExpression();
            this.Current.BExpressionEnded();
        }

        public void StartFunctionCall()
        {
            this.Current.StartFunctionCall();
        }

        public void EndFunctionCall()
        {
            this.Current.EndFunctionCall();
        }
    }
}
